<template>
  <div>
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            v-for="item in photoTobbar"
            :key="item.id"
            class="mui-control-item"
            @click="getAllphoto(item.id)"
          >{{item.title}}</a>
          <span class="mui-control-item"
           @click="getAllTabbar (start=start+5,count=5)"
           >
            更多热映...
          </span>
        </div>
      </div>
    </div>
    <div id="container">
    <ul class="photo-list">
      <li v-for="item in photoList">
        <img v-lazy.container="item.image" referrerpolicy="never"/>
      </li>
      <div class="mui-card-footer" @click="getAllphoto (ids,start=0,count=count+5)">加载更多...</div>
    </ul>
    </div>
  </div>
</template>

<script>
// 导入 mui JS文件，滑动导航栏
import mui from "../../lib/mui-master/dist/js/mui.min.js";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      photoTobbar: [],
      photoList: [],
      start:0,
      count:5,
      ids: "",
      total:1
    };
  },
  created() {
    this.getAllTabbar();
  },
  mounted() {
    // 初始化 操作元素最早在这里
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
    //this.getAllphoto(this.ids)
  },
  methods: {
    getAllTabbar(start=0,count=5) {
      if(start > this.total) {
        Toast("没有了");
        return
      }
      this.$http
        .get("v2/movie/in_theaters?start="+start+"&count="+count)
        .then(result => {
          this.photoTobbar = this.photoTobbar.concat(result.body.subjects);
          this.ids = this.photoTobbar[0].id;
          this.total = result.body.total;
          console.log(result)
        })
        .then(result => {
          if(start !== 0){ // 判断是否是更多热映
            return
          }
          this.getAllphoto(this.ids);
        });
    },
    getAllphoto(ids,start=0,count=5) {
      this.ids = ids;
      this.$http.get("v2/movie/subject/" + ids + "/photos?start="+start+"&count="+count).then(result => {
        this.photoList = result.body.photos;
        console.log(result)
        console.log(this.photoList);
      });
    }
  }
};
</script>

<style lang="scss" scoped>
* {
  /* 解除滑动时的报错 这是Chrome自己的东西*/
  touch-action: pan-y;
}

.mui-slider {
  position: fixed;
  background-color: #efeff4;
  box-shadow: 0 0 6px #999;
}

.mui-card-footer {
  background-color: #fff;
}

.photo-list {
  list-style: none;
  margin: 0;
  margin-bottom: 25px;
  padding: 10px;
  padding-bottom:0;
  padding-top: 50px;
  li {
    background-color: #ccc;
    margin-bottom: 10px;
    box-shadow: 0 0 6px #999;
    img{
      width: 100%;
      vertical-align: middle;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
  }
}
</style>